package com.appspot.didit.client.user;

import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.event.dom.client.HasKeyPressHandlers;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HasText;
import com.google.gwt.user.client.ui.HasValue;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.PasswordTextBox;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

public class LoginView extends Composite implements LoginPresenter.View {
	
	public final Label loginHint;
	
	public final Label usernameLabel;
	
	public final TextBox usernameTb;
	
	public final Label passwordLabel;
	
	public final PasswordTextBox passwordTb;
	
	public final Button loginButton;
	
	public final Button loginResetButton;
	
    public LoginView() {
    	VerticalPanel vp = new VerticalPanel();
    	loginHint = new Label();
    	loginHint.setStylePrimaryName("hints");
        usernameLabel = new Label("Benutzername:");
        usernameTb = new TextBox();
        usernameTb.setWidth("200px");
        
        passwordLabel = new Label("Passwort:");
        passwordTb = new PasswordTextBox();
        passwordTb.setWidth("200px");
        
        loginButton = new Button("Anmelden");
        
        loginResetButton = new Button("Reset");
        
        FlexTable layout = new FlexTable();
        layout.setCellSpacing(6);

        // Add some standard form options
        //layout.setWidget(0, 0, loginHint);
        layout.setWidget(1, 0, usernameLabel);
        layout.setWidget(1, 1, usernameTb);
        layout.setWidget(2, 0, passwordLabel);
        layout.setWidget(2, 1, passwordTb);

        layout.setWidget(3, 0, loginButton);
        layout.setWidget(3, 1, loginResetButton);
        
        vp.add(loginHint);
        vp.add(layout);
        initWidget(vp);
    }

    public Widget getWidget() {
            return this;
    }

	public void reset() {
		loginHint.setText("");
		usernameTb.setValue("");
    	passwordTb.setValue("");
	}
	
	public HasClickHandlers getLoginClickHandlers() {
		return loginButton;
	}
	
	public HasClickHandlers getLoginResetClickHandlers() {
		return loginResetButton;
	}

	@Override
	public HasText getLoginHint() {
		return loginHint;
	}

	@Override
	public HasValue<String> getPassword() {
		return passwordTb;
	}


	@Override
	public HasValue<String> getUsername() {
		return usernameTb;
	}

	public HasKeyPressHandlers getKeyPressHandler() {
		return passwordTb;
	}

}
